<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body {
            margin: 0;
            overflow: hidden;
        }
    </style>
</head>

<body>
    <canvas width="400" height="400" style="background-color: #000;" id="canvas"></canvas>

</body>
<script>
    var canvas = document.getElementById("canvas");
    var ctx = canvas.getContext("2d");

    //获取屏幕对象
    //获取屏幕尺寸
    //屏幕尺寸赋值给画板

    var s = window.screen;
    var w = s.width;
    var h = s.height;
    //设置画板大小
    canvas.width = w;
    canvas.height = h;
    //文字大小
    var fontSize = 14;
    var clos = Math.floor(w / fontSize);//计算一行有多少文字 向下取整

    var drops = [];
    var str = "分享完毕";  //飘屏内容
    for (var i = 0; i < clos; i++) {
        drops.push(0);
    }
    function drawString() {
        //设置填充色
        ctx.fillStyle = "rgba(0,0,0,0.05)"
        //绘制矩形
        ctx.fillRect(0, 0, w, h);
        //添加文字样式
        ctx.font = "600px" + fontSize + "px 微软雅黑"
        ctx.fillStyle = "blue";
        for (var i = 0; i < clos; i++) {
            var x = i * fontSize;
            var y = drops[i] * fontSize;
            ctx.fillText(str[Math.floor(Math.random() * str.length)], x, y);
            if (y > h && Math.random() > 0.99) {
                drops[i] = 0;
            }
            drops[i]++;
        }

    }

    setInterval(drawString, 100);
</script>

</html>